#include "auxclasses.h"
#include <QTreeView>
#include <QMenu>
#include <QAction>

TreeView::TreeView(QWidget *parent) : QTreeView(parent)
{
    this->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
            this, SLOT(showContextMenu(const QPoint &)));
    action_show = new QAction(tr("show"), this);
    action_show->setCheckable(true);
    action_delete = new QAction(tr("delete"), this);
    action_delete->setCheckable(true);
}

void TreeView::showContextMenu(const QPoint &pos)
{
    QModelIndex index = indexAt(pos);
    if (index.parent() != QModelIndex()) {
        QMenu menu(this);
        menu.addAction(action_show);
        menu.addAction(action_delete);
        menu.exec(this->viewport()->mapToGlobal(pos));
        if (action_show->isChecked() == true) {
            emit showData(index);
            action_show->setChecked(false);
        }
        if (action_delete->isChecked() == true) {
            emit deleteFile(index);
            action_delete->setChecked(false);
        }
    }
}
